<?php

namespace app\common\lib\rtc;

use app\aliyun\controller\AliyunRtc;
use think\Log;

class RtcCommon
{
    /**
     * 提出 频道
     * @param $channelId
     * @param $userId
     * @return void
     */
    public function removeTerminals($channelId, $userId)
    {
        // 自动踢出
        $result = (new AliyunRtc())->removeTerminals($channelId, [$userId]);
        //[
        //      'code' => 200,
        //      'msg' => '请求成功!',
        //      'data' =>[
        //           'result' =>[
        //              'RequestId' => '9695BD39-96CC-5E25-812C-DA83E60297C7',
        //              'Terminals' =>[
        //                  'Terminal' => [
        //                         0 =>[
        //                                  'Message' => 'ok',
        //                                  'Id' => '12346392',
        //                                   'Code' => 0,
        //                                ],
        //                  ],
        //              ],
        //          ],
        //      ],
        // ];
        if ($result['code'] === 200 && isset($result['data']['result']['Terminals']['Terminal']) && !empty($result['data']['result']['Terminals']['Terminal']))
        {
            Log::write("连麦回调：用户非法进入连麦，执行踢出操作--成功--；ChannelId:【{$channelId}】uid：【{$userId}】;踢出结果:" . json_encode($result), 'log');
        } else
        {
            Log::write("连麦回调：用户非法进入连麦，执行踢出操作--失败--；ChannelId:【{$channelId}】uid：【{$userId}】;踢出结果:" . json_encode($result), 'error');
        }
    }
}